import { getCookie } from '~/utils'
import axios from 'axios'

export function markVisible () {
  if (process.env.NODE_ENV === 'development') { return }
  window.addEventListener('visibilitychange', () => {
    this.$store.commit('TOGGLE_VISIBLE')
    axios.post('/api/visit', {
      userAgent: navigator.userAgent,
      visible: this.$store.state.isAppVisible,
      markId: getCookie('markId'),
      offset: new Date().getTimezoneOffset(),
      alive: this.$store.state.isAppAlive,
      refer: document.referrer,
      path: this.$route.path,
      date: new Date().toLocaleString()
    })
  })
}

export function markVisit () {
  if (process.env.NODE_ENV === 'development') { return }
  axios.post('/api/visit', {
    userAgent: navigator.userAgent,
    visible: this.$store.state.isAppVisible,
    markId: getCookie('markId'),
    offset: new Date().getTimezoneOffset(),
    alive: this.$store.state.isAppAlive,
    refer: document.referrer,
    path: this.$route.path,
    date: new Date().toLocaleString()
  })
}
